package com.g2.admin.controller;

import com.g2.admin.common.constant.StatusTypeEnums;
import com.g2.admin.model.po.AuthAuthorityPo;
import com.g2.admin.model.po.AuthSystemPo;
import com.g2.admin.service.AuthAuthorityService;
import com.g2.admin.service.AuthSystemService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("sys")
@Api(tags = "Auth")
public class SysController extends BaseController {
    @Autowired
    private AuthSystemService systemService;

    @GetMapping("/list")
    public List<AuthSystemPo> systems() {
        return systemService.getAuthsystems();
    }

    @PostMapping("/add")
    public void addSys(@RequestBody AuthSystemPo systemPo) {
        systemService.addAuthsystem(systemPo);
    }

    @PostMapping("/enable/{code}")
    public void enableSys(@PathVariable("code") String code) {
        systemService.updateAuthsystem(AuthSystemPo.builder().code(code).status(StatusTypeEnums.StatusEnums.ENABLE).build());
    }
    @PostMapping("/disable/{code}")
    public void disableSys(@PathVariable("code") String code) {
        systemService.updateAuthsystem(AuthSystemPo.builder().code(code).status(StatusTypeEnums.StatusEnums.DISABLE).build());
    }

    @PostMapping("/del/{code}")
    public void delSys(@PathVariable("code") String code) {
        systemService.delAuthsystem(code);
    }
}
